﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using FTchina;

public partial class UI_getCustomerList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string groupid = FTchina.basic.SafeRequest(Request["groupid"]);
        int  times =Convert.ToInt32( FTchina.basic.SafeRequest(Request["times"]));
        int count = Convert.ToInt32(FTchina.basic.SafeRequest(Request["count"]));

        Response.Write("[" + AjaxgetCustomerList(groupid,times,count) + "]");

    }

     
    /// <summary>
    /// 供AJax调用
    /// </summary>
    /// <param name="GroupID"></param>
    /// <returns></returns>
    public String AjaxgetCustomerList(string GroupID,int times, int count)
    {
        string NodeList = "  id: '{0}', name: '{2}',tel: '{3}',nocheck: {4},customername:'{5}' ";
        int number = 0;
        string sqllimit = string.Empty;
        if (times > 1)
        {
            number = count * (times - 1);
            sqllimit = " limit " + number + "," + count;
        }
        else
        {
            sqllimit = " limit " + count;

        }


        string tmp = string.Empty;
        string sql = "select * from CustomerList where CustomerGroupID='" + GroupID + "' order by CustomerTel0 asc " + sqllimit;
       // FTchina.basic.Log(sql);
        DataTable dt = shujuku.GetDataTable(sql);
        bool nocheck = true;
        string displayname = string.Empty;//组合显示客户信息
        foreach (DataRow dr in dt.Rows)
        {
            displayname = dr["CustomerName"].ToString() + "，" + dr["CustomerWork"].ToString() + "，" + dr["CustomerTel0"].ToString();
            displayname = displayname.Replace("，，", "，");

            nocheck = !basic.ValidateMobile(dr["CustomerTel0"].ToString().Trim());
            tmp += "{" + string.Format(NodeList, dr["id"], dr["CustomerGroupID"], displayname, dr["CustomerTel0"], "'" + nocheck + "'", dr["CustomerName"].ToString()) + "},";
        }
        if (tmp.EndsWith(",")) tmp = tmp.Substring(0, tmp.Length - 1);
        return tmp;
    }

}